﻿using System;
using System.Collections.Generic;
using System.Text;

namespace XP.Utilities.Utility
{
    public class MadePage
    {
        private string _path = string.Empty;
        private string _url = string.Empty;

        public MadePage(string path, string url)
        {
            _path = path;
            _url = url;
            if (!_url.EndsWith("/")) _url += "/";
        }

        public void Made(string madePage, string htmlPage,System.Text.Encoding encoding)
        {
            string webContent = XP.Utilities.Utility.Http.GetWebContent(_url + madePage);
            if (System.IO.File.Exists(_path + "\\" + htmlPage)) System.IO.File.Delete(_path + "\\" + htmlPage);
            using (System.IO.StreamWriter sw = new System.IO.StreamWriter(_path + "\\" + htmlPage, false, encoding))
            {
                sw.Write(webContent);
                sw.Flush();
                sw.Close();
            }
        }

        public void Made(string madePage,System.Text.Encoding encoding)
        {
            string htmlPage = madePage.Substring(0, madePage.IndexOf(".")) + ".html";
            Made(madePage, htmlPage, encoding);
        }
    }
}
